function y = minDistSearch(pt,model,option)

switch option,
    case 'iterate'
        dist = 1e6;
        for i=1:size(model,2),
            for j=1:size(model{i},3),
                for k=1:size(model{i},1),
%                     dist1 = abs(model{i}(k,1,j) - pt(1,1)) + abs(model{i}(k,2,j) - pt(2,1));
                    dist1 = sqrt((model{i}(k,1,j) - pt(1,1))^2 + (model{i}(k,2,j) - pt(2,1))^2);
                    if dist1 < dist, dist = dist1; end
                end
            end
        end
    case 'analytic'
        dist = 1e6;
        for i=1:size(model,2),
            for j=1:size(model{i},3),
                % get line
                Ax = model{i}(1,1,j);
                Ay = model{i}(1,2,j);
                
                Bx = model{i}(size(model{i},1),1,j);
                By = model{i}(size(model{i},1),2,j);
                
                ptx = pt(1,1); pty = pt(2,1);
                
                dist1 = abs((Bx-Ax)*(Ay-pty) - (Ax-ptx)*(By-Ay))/sqrt((Bx-Ax)^2 + (By-Ay)^2);
                
                if dist1 < dist, dist = dist1; end
            end
        end
    otherwise
        error('Unknown initialization method.');
end
    y = dist;
end